#include "GameOverLayer.h"
#include "PlayScene.h"

USING_NS_CC;

bool GameOverLayer::init()
{
	if(!LayerColor::initWithColor(Color4B(0,0,0,180)))
	{
		return false;
	}

	auto director = Director::getInstance();
	auto winSize = director->getWinSize();
	auto centerPos = Vec2(winSize.width/2, winSize.height/2);

	auto menuItemRestart = MenuItemSprite::create(Sprite::create("restart_n.png"), Sprite::create("restart_s.png"), CC_CALLBACK_1(GameOverLayer::onRestart, this));
	auto menu = Menu::create(menuItemRestart, NULL);
	menu->setPosition(centerPos);
	this->addChild(menu);
}

void GameOverLayer::onRestart(Ref* pSender)
{
	auto playScene = PlayScene::createScene();
	auto director = Director::getInstance();
	director->resume();
	director->replaceScene(playScene);
}